package com.lcf.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dao.ArticleDao;
import com.lcf.system.dto.ArticleDTO;
import com.lcf.system.entity.Article;
import com.lcf.system.query.ArticlePageQuery;
import com.lcf.system.service.ArticleService;
import com.lcf.system.vo.ArticleVO;
import org.springframework.stereotype.Service;

/**
 * 文章(Article)表服务实现类
 *
 * @author lcf
 * @since 2025-04-24 21:14:33
 */
@Service("articleService")
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, Article> implements ArticleService {

    @Override
    public boolean insert(ArticleDTO dto) {
        return BeanUtil.copyProperties(dto, Article.class).insert();
    }

    @Override
    public boolean update(long id, ArticleDTO dto) {
        Article article = BeanUtil.copyProperties(dto, Article.class);
        article.setId(id);
        return article.updateById();
    }

    @Override
    public boolean delete(long id) {
        return removeById(id);
    }

    @Override
    public ArticleVO query(long id) {
        return BeanUtil.copyProperties(getById(id), ArticleVO.class);
    }

    @Override
    public PageVO<ArticleVO> queryPage(ArticlePageQuery query) {
        Page<Article> page = Db.lambdaQuery(Article.class)
                .page(query.toPage());

        return new PageVO<>(page, ArticleVO.class);
    }
}

